<.notice title="Danger zone" theme={:red}>
  Destructive actions below can result in irrecoverable data loss. Be careful.
</.notice>

<.settings_tiles>
  <.tile docs="delete-account">
    <:title>Delete account</:title>
    <:subtitle>Permanently deletes your sites and all collected stats.</:subtitle>

    <%= cond do %>
      <% length(@solely_owned_teams) > 0 -> %>
        <.notice theme={:gray} title="You can't delete your account yet">
          You're the sole owner of one or more teams. To delete your account, either add another owner or delete each of the following team(s):
          <ul class="w-full py-4">
            <li :for={team <- @solely_owned_teams} class="pt-1">
              <.styled_link href={
                Routes.settings_path(@conn, :team_general, __team: team.identifier)
              }>
                {Plausible.Teams.name(team)}
              </.styled_link>
            </li>
          </ul>
        </.notice>
      <% Plausible.Billing.Subscription.Status.active?(@my_team && @my_team.subscription) -> %>
        <.notice theme={:gray} title="You can't delete your account yet">
          You have an active subscription. To delete your account, cancel your subscription first.
        </.notice>
      <% true -> %>
        <.button_link
          data-confirm="Deleting your account will also delete all the sites and data that you own. This action cannot be reversed. Are you sure?"
          href="/me"
          method="delete"
          theme="danger"
          mt?={false}
        >
          Delete my account
        </.button_link>
    <% end %>
  </.tile>
</.settings_tiles>
